package com.nbwyctf.helper.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chetaifu
 */
public class PageUtil {
    public static <T> List<T> getPaginateData(List<T> list, Integer pageSize, Integer currentPage) {
        List<T> result = new ArrayList<>();
        // 总条数
        int size = list.size();
        if (currentPage <= 0 || pageSize <= 0) {
            return result;
        }
        int startInclusion = (currentPage - 1) * pageSize;
        if (startInclusion >= size) {
            return result;
        }
        int endExclusion = startInclusion + pageSize;
        if (endExclusion > size) {
            endExclusion = size;
        }
        result = list.subList(startInclusion, endExclusion);
        return result;
    }
}
